function onMapsClick(param)
{
    if (!geoName) {
        jQuery("input[name='geo_name']").val('');
        jQuery("input[name='national_id']").val('');
        jQuery("input[name='geo_level']").val('');
    } else {
        var geoLevel = getGeoLevel(geoName);
        var nationalID = getNationalID(geoLevel, geoName);
        jQuery("input[name='geo_name']").val(geoName);
        jQuery("input[name='national_id']").val(nationalID);
        jQuery("input[name='geo_level']").val(geoLevel);
    }
}

/*******************************画面相关************************************/
function getDistributorStockInfoStat(){
    jQuery.ajaxSettings.async = false;
    var params = [];
    var geoLevel = getGeoLevel(geoName);
    var nationalID = getNationalID(geoLevel, geoName);
    params.push('parameters[geo_name]=' + (!geoName ? geoChain[geoChain.length-1] : geoName));
    params.push('parameters[geo_level]=' + geoLevel);
    params.push('parameters[national_id]=' + nationalID);
    params.push('parameters[year]=' + jQuery("select[name='year']").val());
    params.push('parameters[month]=' + jQuery("select[name='month']").val());

    jQuery.getJSON(nonghuaBaseUrl + '/api/stock_info?' + params.join('&'), function (json) {
        optionYoY_thisMonthStock.xAxis[0].data = json.YoY_thisMonthStock.times;
        optionYoY_thisMonthStock.series[0].data = json.YoY_thisMonthStock.values;
        barChartYoY_thisMonthStock.setOption(optionYoY_thisMonthStock, true);

        optionQoQ_thisMonthStock.legend.data = json.QoQ_thisMonthSales.legend;
        optionQoQ_thisMonthStock.xAxis[0].data = json.QoQ_thisMonthSales.xAxis;
        optionQoQ_thisMonthStock.series = json.QoQ_thisMonthSales.yAxis;
        barChartQoQ_thisMonthStock.setOption(optionQoQ_thisMonthStock, true);
        jQuery('#myModal').modal('show');
    });
}
function getDistributorStockInfoStats(distributorID, year, month,sacfvarietyID)
{
    jQuery.ajaxSettings.async = false;
    var params = [];

    params.push('parameters[distributor_id]=' + distributorID);
    params.push('parameters[sacfvariety_id]=' + sacfvarietyID);
    params.push('parameters[year]=' + jQuery("select[name='year']").val());
    params.push('parameters[month]=' + jQuery("select[name='month']").val());

    jQuery.getJSON(nonghuaBaseUrl + '/api/stock_info_for_distributor?' + params.join('&'), function (json) {
        optionYoY_thisMonthStock.xAxis[0].data = json.YoY_thisMonthStock.times;
        optionYoY_thisMonthStock.series[0].data = json.YoY_thisMonthStock.values;
        barChartYoY_thisMonthStock.setOption(optionYoY_thisMonthStock, true);

        optionQoQ_thisMonthStock.legend.data = json.QoQ_thisMonthSales.legend;
        optionQoQ_thisMonthStock.xAxis[0].data = json.QoQ_thisMonthSales.xAxis;
        optionQoQ_thisMonthStock.series = json.QoQ_thisMonthSales.yAxis;
        barChartQoQ_thisMonthStock.setOption(optionQoQ_thisMonthStock, true);
    });
}


function getjurisStockStats()
{
    jQuery.ajaxSettings.async = false;
    var params = [];
    if(jQuery("select[name='juris']").val() == ""){
        alert('区域为必选！'); return false;
    }
    params.push('parameters[distributor]=' + jQuery("select[name='distributor']").val());
    params.push('parameters[juris]=' + jQuery("select[name='juris']").val());
    params.push('parameters[salesman]=' + jQuery("select[name='salesman']").val());
    params.push('parameters[year]=' + jQuery("select[name='year']").val());
    params.push('parameters[month]=' + jQuery("select[name='month']").val());

    jQuery.getJSON(nonghuaBaseUrl + '/api/stock_info_by_zone?' + params.join('&'), function (json) {
        optionYoY_thisMonthStock.xAxis[0].data = json.YoY_thisMonthStock.times;
        optionYoY_thisMonthStock.series[0].data = json.YoY_thisMonthStock.values;
        barChartYoY_thisMonthStock.setOption(optionYoY_thisMonthStock, true);

        optionQoQ_thisMonthStock.legend.data = json.QoQ_thisMonthSales.legend;
        optionQoQ_thisMonthStock.xAxis[0].data = json.QoQ_thisMonthSales.xAxis;
        optionQoQ_thisMonthStock.series = json.QoQ_thisMonthSales.yAxis;
        barChartQoQ_thisMonthStock.setOption(optionQoQ_thisMonthStock, true);
        jQuery('#myModal').modal('show');
    });
}

/*******************************图表相关************************************/
/* 柱状图  */
var optionYoY_thisMonthStock = {
    show : true,
    tooltip : {
        trigger: 'axis'
    },
    toolbox: {
        show : false
    },
    color : [ '#00a0a0' ],
    calculable : false,
    xAxis : [
        {
            type : 'category',
            data : []
        }
    ],
    yAxis : [
        {
            type : 'value'
        }
    ],
    series : [
        {
            type: 'bar',
            data: []
        }
    ]
};
var optionQoQ_thisMonthStock = {
    title : {
        //text: '库存',
    },
    tooltip : {
        trigger: 'axis',
    },
    legend: {
        data:[]
    },
    calculable : false,
    xAxis : [
        {
            type : 'category',
            boundaryGap : false,
            data : []
        }
    ],
    yAxis : [
        {
            type : 'value'
        }
    ],
    series : [

    ]
};

var barChartYoY_thisMonthStock = echarts.init(document.getElementById('divYoY_thisMonthStock'));
var barChartQoQ_thisMonthStock = echarts.init(document.getElementById('divQoQ_thisMonthStock'));

jQuery(function($) {
    initMap("#map_previous", "#map_next");
    $(".content").addClass('map');
    $("#block-system-main").addClass('map');
    $("#map").button("toggle");
    $("#zone-wrapper-div").hide();

    $("#map").click(function (e) {
        e.preventDefault();
        $("#zone-wrapper-div").slideUp();
        $("#map-wrapper-div").slideDown();
        $(".content").addClass('map');
        $(".content").removeClass('zone');
        $("input[name='map_or_zone']").val('map');
        $("#stockinfoStat").show();
        $("#jurisStockStat").hide();
    });

    $("#zone").click(function (e) {
        e.preventDefault();
        $("#map-wrapper-div").slideUp();
        $("#zone-wrapper-div").slideDown();
        $(".content").addClass('zone');
        $(".content").removeClass('map');
        $("input[name='map_or_zone']").val('zone');
        $("#stockinfoStat").hide();
        $("#jurisStockStat").attr("style","display:block;clear:both");
    });
});
